package top.hekun.study.core.visitor.complex;

import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.SimpleRemapper;
import top.hekun.study.core.model.HelloWord;

import java.util.HashMap;
import java.util.Map;

/**
 * 复杂的类修改示例
 * 〈修改类名〉
 *
 * @author: Sakura
 * @date: 2023/5/16
 */
public class MyClassVisitor1 extends ClassRemapper {
         private static Remapper remapper;
    static {
        Map<String,String> mapper = new HashMap<>();
        // 修改类名
        String className = Type.getType(HelloWord.class).getInternalName();
        mapper.put(className,"top/hekun/study/model/HelloWordComplexModifyClass");
        // 修改 字段名
        mapper.put(className+"."+"newIntValue","a");
        // 修改方法名
        mapper.put(className+"."+"test0()V","test000");

        remapper = new SimpleRemapper(mapper);
    }
    public MyClassVisitor1(int apiVersion, ClassVisitor classWriter) {
        super(apiVersion, classWriter,remapper);
    }


}
